home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Fudd Source / Fudd ƒ / Fudd code ƒ / fudd meat.c < prev    next >
Text File  |  1994-02-07  |  3KB  |  124 lines

  1. /**********************************************************************\
  2.  
  3. File:        fudd meat.c
  4.  
  5. Purpose:    This module handles actually converting text into Fudd talk.
  6.  
  7.  
  8. Fudd -=- convert text to Elmer Fudd talk
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "fudd meat.h"
  29. #include "program globals.h"
  30.  
  31. unsigned long    gInputOffset;
  32. unsigned long    gOutputOffset;
  33. Ptr                gInputBuffer;
  34. Ptr                gOutputBuffer;
  35. Boolean            gInputNeedsUpdate;
  36. Boolean            gOutputNeedsUpdate;
  37. unsigned long    gAbsoluteOffset;
  38. unsigned long    gInputLength;
  39.  
  40. void ConvertIt(void)
  41. {
  42.     char            oneChar;
  43.     
  44.     oneChar=(ThisChar())|0x20;
  45.     
  46.     if ((oneChar=='r') || (oneChar=='l'))
  47.     {
  48.         StoreChar(ThisChar()+'w'-oneChar);
  49.         InputPlus(1);
  50.         return;
  51.     }
  52.     
  53.     if ((oneChar=='q') && ((NextChar(1)|0x20)=='u'))
  54.     {
  55.         StoreChar(ThisChar());
  56.         StoreChar(NextChar(1)+'w'-'u');
  57.         InputPlus(2);
  58.         return;        
  59.     }
  60.     
  61.     if ((oneChar=='t') && ((NextChar(1)|0x20)=='h') && (NextChar(2)==' '))
  62.     {
  63.         StoreChar(ThisChar()+'f'-'t');
  64.         InputPlus(2);
  65.         return;
  66.     }
  67.     
  68.     if ((oneChar=='t') && ((NextChar(1)|0x20)=='h'))
  69.     {
  70.         StoreChar(ThisChar()+'d'-'t');
  71.         InputPlus(2);
  72.         return;
  73.     }
  74.     
  75.     if ((oneChar=='n') && (NextChar(1)=='.'))
  76.     {
  77.         StoreString("\pn, uh-hah-hah-hah");
  78.         InputPlus(1);
  79.         return;
  80.     }
  81.     
  82.     StoreChar(ThisChar());
  83.     InputPlus(1);
  84. }
  85.  
  86. char ThisChar(void)
  87. {
  88.     if (gInputOffset>=INPUT_BUFFER_MAX)
  89.         gInputNeedsUpdate=TRUE;
  90.     if (gAbsoluteOffset>=gInputLength)
  91.         return 0x00;
  92.     else
  93.         return *((char*)((long)gInputBuffer+gInputOffset));
  94. }
  95.  
  96. char NextChar(int howmany)
  97. {
  98.     if (gAbsoluteOffset+howmany>=gInputLength)
  99.         return 0x00;
  100.     else
  101.         return *((char*)((long)gInputBuffer+gInputOffset+howmany));
  102. }
  103.  
  104. void StoreChar(char thisChar)
  105. {
  106.     *((char*)((long)gOutputBuffer+(gOutputOffset++)))=thisChar;
  107.     if (gOutputOffset>=OUTPUT_BUFFER_MAX)
  108.         gOutputNeedsUpdate=TRUE;
  109. }
  110.  
  111. void StoreString(Str255 thisString)
  112. {
  113.     int                i;
  114.     
  115.     for (i=1; i<=thisString[0]; i++)
  116.         StoreChar(thisString[i]);
  117. }
  118.  
  119. void InputPlus(int howmany)
  120. {
  121.     gInputOffset+=howmany;
  122.     gAbsoluteOffset+=howmany;
  123. }
  124.